home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / misc / gs261src.zip / zfont1.c < prev    next >
C/C++ Source or Header  |  1993-05-26  |  8KB  |  213 lines

  1. /* Copyright (C) 1991, 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* zfont1.c */
  20. /* Type 1 font creation operator for Ghostscript */
  21. #include "ghost.h"
  22. #include "errors.h"
  23. #include "oper.h"
  24. #include "gxfixed.h"
  25. #include "gsmatrix.h"
  26. #include "gxdevice.h"
  27. #include "gschar.h"
  28. #include "gxfont.h"
  29. #include "bfont.h"
  30. #include "dict.h"
  31. #include "dparam.h"
  32. #include "iname.h"
  33. #include "store.h"
  34.  
  35. /* Type 1 auxiliary procedures (defined in zchar.c) */
  36. extern int z1_subr_proc(P3(gs_type1_data *, int, const byte **));
  37. extern int z1_pop_proc(P2(gs_type1_data *, fixed *));
  38.  
  39. /* Names of system-known keys in font dictionaries: */
  40. static ref name_PaintType;
  41. static ref name_Type1BuildChar;
  42. static ref name_Type1BuildGlyph;
  43. static ref name_Private;
  44. static ref name_CharStrings;        /* only needed for seac */
  45. /* Names of system-known keys in type 1 font Private dictionary: */
  46. static ref name_BlueFuzz;
  47. static ref name_BlueScale;
  48. static ref name_BlueShift;
  49. static ref name_BlueValues;
  50. static ref name_ExpansionFactor;
  51. static ref name_FamilyBlues;
  52. static ref name_FamilyOtherBlues;
  53. static ref name_ForceBold;
  54. static ref name_LanguageGroup;
  55. static ref name_lenIV;
  56. static ref name_OtherBlues;
  57. static ref name_RndStemUp;
  58. static ref name_StdHW;
  59. static ref name_StdVW;
  60. static ref name_StemSnapH;
  61. static ref name_StemSnapV;
  62. static ref name_Subrs;
  63.  
  64. /* Default value of lenIV */
  65. #define default_lenIV 4
  66.  
  67. /* Initialize the font building operators */
  68. private void
  69. zfont1_init(void)
  70. {    static const names_def fnd1[] = {
  71.  
  72.     /* Create the names of the standard elements of */
  73.     /* a font dictionary. */
  74.        { "PaintType", &name_PaintType },
  75.        { "Type1BuildChar", &name_Type1BuildChar },
  76.        { "Type1BuildGlyph", &name_Type1BuildGlyph },
  77.        { "Private", &name_Private },
  78.        { "CharStrings", &name_CharStrings },
  79.  
  80.     /* Create the names of the known entries in */
  81.     /* a type 1 font Private dictionary. */
  82.        { "BlueFuzz", &name_BlueFuzz },
  83.        { "BlueScale", &name_BlueScale },
  84.        { "BlueShift", &name_BlueShift },
  85.        { "BlueValues", &name_BlueValues },
  86.        { "ExpansionFactor", &name_ExpansionFactor },
  87.        { "FamilyBlues", &name_FamilyBlues },
  88.        { "FamilyOtherBlues", &name_FamilyOtherBlues },
  89.        { "ForceBold", &name_ForceBold },
  90.        { "LanguageGroup", &name_LanguageGroup },
  91.        { "lenIV", &name_lenIV },
  92.        { "OtherBlues", &name_OtherBlues },
  93.        { "RndStemUp", &name_RndStemUp },
  94.        { "StdHW", &name_StdHW },
  95.        { "StdVW", &name_StdVW },
  96.        { "StemSnapH", &name_StemSnapH },
  97.        { "StemSnapV", &name_StemSnapV },
  98.        { "Subrs", &name_Subrs },
  99.  
  100.     /* Mark the end of the initialized name list. */
  101.        names_def_end
  102.     };
  103.  
  104.     init_names(fnd1);
  105.  
  106.     /* Make the standard BuildChar/BuildGlyph procedures executable. */
  107.     r_set_attrs(&name_Type1BuildChar, a_executable);
  108.     r_set_attrs(&name_Type1BuildGlyph, a_executable);
  109. }
  110.  
  111. /* <string|name> <font_dict> .buildfont1 <string|name> <font> */
  112. /* Build a type 1 (Adobe encrypted) font. */
  113. int
  114. zbuildfont1(os_ptr op)
  115. {    gs_type1_data data1;
  116.     ref *psubrs;
  117.     ref *pcharstrings;
  118.     ref *pprivate;
  119.     static ref no_subrs;
  120.     gs_font *pfont;
  121.     font_data *pdata;
  122.     int code;
  123.     check_type(*op, t_dictionary);
  124.     code = dict_int_param(op, &name_PaintType, 0, 3, 0, &data1.PaintType);
  125.     if ( code < 0 ) return code;
  126.     if ( dict_find(op, &name_CharStrings, &pcharstrings) <= 0 ||
  127.         !r_has_type(pcharstrings, t_dictionary) ||
  128.         dict_find(op, &name_Private, &pprivate) <= 0 ||
  129.         !r_has_type(pprivate, t_dictionary)
  130.        )
  131.         return_error(e_invalidfont);
  132.     if ( dict_find(pprivate, &name_Subrs, &psubrs) > 0 )
  133.        {    check_array_else(*psubrs, e_invalidfont);
  134.        }
  135.     else
  136.        {    make_tasv(&no_subrs, t_string, 0, 0, bytes, (byte *)0),
  137.         psubrs = &no_subrs;
  138.        }
  139.     /* Get the rest of the information from the Private dictionary. */
  140.     if ( (code = dict_int_param(pprivate, &name_lenIV, 0, 255,
  141.                     default_lenIV, &data1.lenIV)) < 0 ||
  142.          (code = dict_int_param(pprivate, &name_BlueFuzz, 0, 1999, 1,
  143.                     &data1.BlueFuzz)) < 0 ||
  144.          (code = dict_float_param(pprivate, &name_BlueScale, 0.039625,
  145.                       &data1.BlueScale)) < 0 ||
  146.          (code = dict_float_param(pprivate, &name_BlueShift, 7.0,
  147.                     &data1.BlueShift)) < 0 ||
  148.          (code = data1.BlueValues.count = dict_float_array_param(pprivate,
  149.         &name_BlueValues, max_BlueValues * 2,
  150.         &data1.BlueValues.values[0], NULL)) < 0 ||
  151.          (code = dict_float_param(pprivate, &name_ExpansionFactor, 0.06,
  152.                       &data1.ExpansionFactor)) < 0 ||
  153.          (code = data1.FamilyBlues.count = dict_float_array_param(pprivate,
  154.         &name_FamilyBlues, max_FamilyBlues * 2,
  155.         &data1.FamilyBlues.values[0], NULL)) < 0 ||
  156.          (code = data1.FamilyOtherBlues.count = dict_float_array_param(pprivate,
  157.         &name_FamilyOtherBlues, max_FamilyOtherBlues * 2,
  158.         &data1.FamilyOtherBlues.values[0], NULL)) < 0 ||
  159.          (code = dict_bool_param(pprivate, &name_ForceBold, 0,
  160.                      &data1.ForceBold)) < 0 ||
  161.          (code = dict_int_param(pprivate, &name_LanguageGroup, 0, 1, 0,
  162.                     &data1.LanguageGroup)) < 0 ||
  163.          (code = data1.OtherBlues.count = dict_float_array_param(pprivate,
  164.         &name_OtherBlues, max_OtherBlues * 2,
  165.         &data1.OtherBlues.values[0], NULL)) < 0 ||
  166.          (code = dict_bool_param(pprivate, &name_RndStemUp, 0,
  167.                      &data1.RndStemUp)) < 0 ||
  168.          (code = data1.StdHW.count = dict_float_array_param(pprivate,
  169.         &name_StdHW, 1, &data1.StdHW.values[0], NULL)) < 0 ||
  170.          (code = data1.StdVW.count = dict_float_array_param(pprivate,
  171.         &name_StdVW, 1, &data1.StdVW.values[0], NULL)) < 0 ||
  172.          (code = data1.StemSnapH.count = dict_float_array_param(pprivate,
  173.         &name_StemSnapH, max_StemSnap,
  174.         &data1.StemSnapH.values[0], NULL)) < 0 ||
  175.          (code = data1.StemSnapV.count = dict_float_array_param(pprivate,
  176.         &name_StemSnapV, max_StemSnap,
  177.         &data1.StemSnapV.values[0], NULL)) < 0
  178.        )
  179.         return code;
  180.     /* Do the work common to all non-composite font types. */
  181.     {    static const build_proc_refs build = {
  182.             &name_Type1BuildChar, &name_Type1BuildGlyph
  183.         };
  184.         code = build_gs_simple_font(op, &pfont, ft_encrypted, &build);
  185.     }
  186.     if ( code != 0 ) return code;
  187.     /* This is a new font, fill it in. */
  188.     pdata = (font_data *)pfont->client_data;
  189.     pfont->data.base.type1_data = data1;
  190.     ref_assign(&pdata->CharStrings, pcharstrings);
  191.     ref_assign(&pdata->Subrs, psubrs);
  192.     pfont->data.base.type1_data.subr_proc = z1_subr_proc;
  193.     pfont->data.base.type1_data.pop_proc = z1_pop_proc;
  194.     pfont->data.base.type1_data.proc_data = (char *)pdata;
  195.     /* Check that the UniqueIDs match.  This is part of the */
  196.     /* Adobe protection scheme, but we may as well emulate it. */
  197.     if ( uid_is_valid(&pfont->data.base.UID) )
  198.     {    gs_uid uid;
  199.         if ( get_gs_font_uid(op, &uid) < 0 ||
  200.              !uid_equal(&pfont->data.base.UID, &uid)
  201.            )
  202.             uid_set_invalid(&pfont->data.base.UID);
  203.     }
  204.     return define_gs_font(pfont);
  205. }
  206.  
  207. /* ------ Initialization procedure ------ */
  208.  
  209. op_def zfont1_op_defs[] = {
  210.     {"2.buildfont1", zbuildfont1},
  211.     op_def_end(zfont1_init)
  212. };
  213.